﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Documentanalysis
{
    public class Document
    {
        public string name { get; set; }
        public DirectoryInfo dir { get; set; }
        public int currentFolderCount { get; set; }
        public int currentFileCount { get; set; }
        public int totalFolderCount { get; set; }
        public int totalFileCount { get; set; }
        public Dictionary<string, int> currentTypes
        {
            get
            {
                return currentT;
            }
            set
            {
                currentT = value;
            }
        }
        public Dictionary<string, int> totalTypes
        {
            get
            {
                return totalT;
            }
            set
            {
                totalT = value;
            }
        }
        public List<Document> sons { get; set; }
        public Dictionary<string, int> currentT = new Dictionary<string, int>();
        public Dictionary<string, int> totalT = new Dictionary<string, int>();

        public override string ToString()
        {
            string t = "";
            string r = "\"name\": \"" + name + "\", ";
            if (dir != null)
            {
                r += "\"fullName\": " + dir.FullName + ", ";
            }
            r += "\"currentFolderCount\": " + currentFolderCount + ", ";
            r += "\"currentFileCount\": " + currentFileCount + ", ";
            r += "\"totalFolderCount\": " + totalFolderCount + ", ";
            r += "\"totalFileCount\": " + totalFileCount + ", ";

            t = "";
            foreach (KeyValuePair<string, int> kvp in currentT)
            {
                if (t.Equals(""))
                {
                    t = "{\"key\": \"" + kvp.Key + "\", \"value\": " + kvp.Value + "}";
                }
                else
                {
                    t += ", " + "{\"key\": \"" + kvp.Key + "\", \"value\": " + kvp.Value + "}";
                }
            }
            r += "\"currentT\":[" + t + "], ";

            t = "";
            foreach (KeyValuePair<string, int> kvp in totalT)
            {
                if (t.Equals(""))
                {
                    t = "{\"key\": \"" + kvp.Key + "\", \"value\": " + kvp.Value + "}";
                }
                else
                {
                    t += ", " + "{\"key\": \"" + kvp.Key + "\", \"value\": " + kvp.Value + "}";
                }
            }
            r += "\"totalT\":[" + t + "], ";

            t = "";
            foreach (var doc in sons)
            {
                if (t.Equals(""))
                {
                    t = doc.ToString();
                }
                else
                {
                    t += ", " + doc.ToString();
                }
            }
            r += "\"sons\":[" + t + "]";
            r = "{" + r + "}";
            return r;
        }
    }
}
